package com.reservationserver.service.impl.user;

import com.reservationpojo.domin.po.Getuserpo;
import com.reservationpojo.domin.vo.Adduservo;
import com.reservationpojo.domin.vo.Getuservo;
import com.reservationpojo.entity.User;
import com.reservationserver.mapper.user.Usermapper;
import com.reservationserver.service.user.Userservice;
import lombok.RequiredArgsConstructor;

import org.springframework.stereotype.Service;


import java.util.ArrayList;
import java.util.List;

import static java.lang.Math.min;

@Service
@RequiredArgsConstructor
public class Userserviceimpl implements Userservice {

private final Usermapper usermapper;

    @Override
    public Getuserpo getUserservice(Getuservo getuservo) {
        int page=(getuservo.getPageNumber()-1)*10;
        List<User> users=usermapper.getusermapper(getuservo,page);
        if(users==null){
            return null;
        }
        Getuserpo getuserpo=new Getuserpo();
        getuserpo.setUserList(users);
        return getuserpo;
    }

    @Override
    public void black(String id) {
        usermapper.update(id);
    }

    @Override
    public void unblack(String id) {
        usermapper.unupdate(id);
    }

    @Override
    public void deleteuser(List<String> userIds) {
        usermapper.deleteuser(userIds);
    }

    @Override
    public void adduser(Adduservo uservo) {
        if(uservo.getStartDate()!=null){
            uservo.setGraduationDate(uservo.getStartDate().plusYears(4));
        }

        usermapper.adduser(uservo);
    }
    @Override
    public User upguard(String id) {
        User user=usermapper.upguard(id);
        return user;
    }
    @Override
    public User upunguard(String id) {
        User user=usermapper.upunguard(id);
        return user;
    }
    @Override
    public void deleteTime() {
        usermapper.deleteTime();
    }

    @Override
    public User getusercl(String id) {

        return  usermapper.getusercl(id);
    }
}
